<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form_mymsg" class="layui-form-item wx-search">
            <div class="layui-inline">
                <select name="status" class="layui-input">
                    <option value="">全部</option>
                    <option value="0">未读</option>
                    <option value="1">已读</option>
                </select>
            </div>
            <button class="layui-btn btn-primary" id="search_mytask">搜索</button>
        </div>
        <table id="list_table_mytask" class="layui-hide" lay-filter="mainList_mymsg"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo_mytask">
    <div class="layui-btn-container">
<!--        <button class="layui-btn layui-btn-sm" lay-event="">发布新任务</button>-->
    </div>
</script>
<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var tableObj = table.render({
            elem: '#list_table_mytask'
            , url: context + '/api/sysMsg/list',
            //开启头部工具栏，并为其绑定左侧模板，
            toolbar: '#toolbarDemo_mytask'
            , request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , defaultToolbar: ['filter', 'exports', 'print']
            , align: 'center'
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'},
                {field: 'msg_id', title: 'ID', align: 'center'},
                {field: 'title', title: '标题', align: 'center'},
                {field: 'content', title: '内容', align: 'center'},
                {field: 'status', title: '状态', align: 'center', templet: function (d) {return d.status==0?"未读":"已读"}},
                {field: 'type', title: '类型', align: 'center', templet: function (d) {
                        switch(d.type){case 0: return '系统消息'; case 1: return  '通知消息';default: return '';}}},
                {field: 'userType', title: '人群', align: 'center', templet: function(d){return d.userType==3?"教师":d.userType==4?"学生":d.userType==-1?"私聊":"全部";}},
                {field: 'createDate', title: '发送时间', align: 'center'},
                {title: '发件人', align: 'center',templet: function(d){return d._fromUser? d._fromUser.nickname:"匿名"}},
                {title: '操作', unresize: true, align: 'center',
                    templet: function (d) {
                        return '<a href="javascript:;" class="font-primary" lay-event="read">已读</a>';

                    }}
            ]]
            , page: true
        });
        // 检索
        $("#search_mytask").click(function () {
            reloadTable(tableObj,'list_form_mymsg');
        });

        //表格内部操作按钮监听
        table.on('tool(mainList_mymsg)', function (obj) { //注：tool是工具条事件名，mainList_mytask是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'read') {//已读
                $.ajax({
                    url: context + '/api/sysMsg/updateStatus/'+data.msg_id,
                    type: 'patch',
                    success: function (r) {
                        if(r.success){
                            showAlert('阅读成功');
                            reloadTable(tableObj);
                        }
                    }
                });
            }
        });

    });
</script>
